import 'package:flutter/material.dart';
//导入所有的路由页面
import '../view/index_page.dart';
import '../view/light_belt.dart';

//配置路由
final routes = {
  //初始化路由页面不一定是斜杠 取决于在入口文件怎么定的的
  "/": (context,) => IndexPages(),
  //可选参数定义 				一						二			三
  // "/Search": (context, {arguments}) => SearchPage(arguments: arguments),
  //不需要传参的默认定义方式
  '/light_belt': (context,) => LightBeltPages(),
  // "/NewPage": (context, {arguments}) => NewPage(arguments: arguments),
};

//可以把下面当做固定写法,官方命名路由的改进
// ignore: missing_return, top_level_function_literal_block
var onGenerateRoute = (RouteSettings settings) {
  final String? name = settings.name;
  final Function pageContentBuilder = routes[name] as Function;
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
      MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};